from rest_framework.viewsets import ModelViewSet

from apps.goods.models import GoodsChannel, GoodsChannelGroup, GoodsCategory
from apps.meiduo_admin.paginations import MyPage
from apps.meiduo_admin.serializers.channel_serializers import GoodsChannelSerializers, GoodsChannelGroupSerializers, \
    GoodsCategorySerializers


class GoodsChannelView(ModelViewSet):

    queryset = GoodsChannel.objects.all()
    serializer_class = GoodsChannelSerializers
    pagination_class = MyPage

    def get_queryset(self):

        pk = self.kwargs.get("pk")
        if pk:
            return self.queryset.filter(pk=pk)
        return self.queryset.all()


class GoodsChannelGroupView(ModelViewSet):
    queryset = GoodsChannelGroup.objects.all()
    serializer_class =GoodsChannelGroupSerializers



class GoodsCategorylView(ModelViewSet):
    queryset = GoodsCategory.objects.all()
    serializer_class =GoodsCategorySerializers


